package com.mayinghao.stat;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class GetDir {
	public void write(String dir){
		String maildir="D://ymailserver/apps/ymailserver/var/mail/inboxes/"+dir+"/directory.cfg";
		String temp="D://maildir_w.txt";
		try {
			
			FileReader input = new FileReader(maildir);
			BufferedReader br = new BufferedReader(input);
			FileWriter output = new FileWriter(temp);
			BufferedWriter bw = new BufferedWriter(output);
			int i=0;
			String s = br.readLine();			
			while ( s!=null) {
		 if(i!=4)
				{
			 if(i==5)
			 {
				bw.write("\\u8BED\\u97F3\\u7BB1=/yy"); 
			 }
			 else if(i==6)
			 {
				 bw.write("\\u4F20\\u771F\\u7BB1=/cz");
			 }
			 else{
			    bw.write(s);
			 }
				bw.newLine();
		 }		
				s = br.readLine();
				i++;
			}			
			br.close();
			bw.close();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public void read(String dir){
		try {
			String maildir="D://ymailserver/apps/ymailserver/var/mail/inboxes/"+dir+"/directory.cfg";
			String temp="D://maildir_w.txt";
			
			FileReader input_temp = new FileReader(temp);
			BufferedReader br_temp = new BufferedReader(input_temp);
			FileWriter output_temp = new FileWriter(maildir);
			BufferedWriter bw_temp = new BufferedWriter(output_temp);
	
		
			String str = br_temp.readLine();			
			while ( str!=null) {
			    bw_temp.write(str);
				bw_temp.newLine();
				str=br_temp.readLine();
		}			
			br_temp.close();
			bw_temp.close();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public String update(String maildir){
		try {
			
			String temp="";
			temp=maildir;
			FileReader input_temp = new FileReader(temp);
			BufferedReader br_temp = new BufferedReader(input_temp);
		
		
			String str = br_temp.readLine();			
			while ( str!=null) {
				System.out.println(str);
				new GetDir().write(str);
				new GetDir().read(str);
				str=br_temp.readLine();
		}			
			br_temp.close();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		return "0";
	}
	public static void main(String[] args) {
	new GetDir().update("D://maildir.txt");
	}

}
